package numbers.primenumbers;

import java.util.ArrayList;
import java.util.List;

public class PrimeNumbersGenerator {

	List<Long> previousSimpleNumbers = new ArrayList<Long>();

	public static void main(String[] args) {

		PrimeNumbersGenerator pn = new PrimeNumbersGenerator();

		List<Long> primeNumbers = pn.getPrimeNumbers(100);

		System.out.println(primeNumbers);
		System.out.println(primeNumbers.size());

	}

	private List<Long> getPrimeNumbers(long interval) {

		for (long index = 0; index < interval; index++) {
			if (isPrimeNumber(index)) {
				previousSimpleNumbers.add(index);
			}
		}

		return previousSimpleNumbers;
	}

	private boolean isPrimeNumber(Long number) {
		// check negative
		if (number < 2) {
			return false;
		}

		// check divisors
		for (Long currentNumber : previousSimpleNumbers) {

			Long div = number % currentNumber;
			if (div == 0) {
				return false;
			}

		}

		return true;
	}

}
